import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Test {

	public static void main(String[] args) {
			try {
				Class.forName("com.mysql.jdbc.Driver");
				String url = "jdbc:mysql://localhost:3306/st?useUnicode=true&characterEncoding=utf-8";
				String user = "root";
				String pass = "123456";
				Connection con = DriverManager.getConnection(url,user,pass);
				Statement  st  = con.createStatement();
				ResultSet rs = st.executeQuery("select * from student2");
				while(rs.next()) {
System.out.println("学号:"+rs.getString("sno")+
				   ",院系:"+rs.getString("sdep")+
				   ",性别:"+rs.getString("ssex")+
				   ",年龄:"+rs.getString("sage")+
				   ",姓名:"+rs.getString("sname"));
				}
				rs.close();
				st.close();
				con.close();
				
			} catch (ClassNotFoundException e) {
				
				e.printStackTrace();
			} catch (SQLException e) {
				
				e.printStackTrace();
			}
	}
}
